clear all
set more off

use "all_state_level_epu.dta"

encode state, gen(state_code)
gen period = (year + (month/12))*12
tsset state_code period

***Winsorize
foreach var of varlist EPU* {
	sum `var' if `var'!=0,d
	replace `var' = r(p99) if `var'!=. & `var'>r(p99)
	replace `var' = r(p1) if `var'!=. & `var'<r(p1)
}

foreach var of varlist EPU* {
	gen l`var' = ln(`var')
}

tsset
gen dEPU_National = d.EPU_National
gen dEPU_State = d.EPU_State
gen dlEPU_National = d.lEPU_National
gen dlEPU_State = d.lEPU_State

STOP STOP STOP 

******************************************************************************************************
*****Figure A3: Event Case studies
******************************************************************************************************
***Debt Ceiling Dispute
sum dlEPU_National if year==2011 & month==7,d
local med = r(p50)
di `med'
twoway (hist dlEPU_National if year==2011 & month==7, width(.25) fc(none) fraction xlabel(,labsize(large)) xtitle(,size(large)) ylabel(,labsize(large)) ytitle(,size(large)) xline(`med', lc(red)))
graph export "Results/hist_debt_ceiling.png", height(600) width(900) replace

***Shutdown 2013
sum dlEPU_National if year==2013 & month==10,d
local med = r(p50)
di `med'
twoway (hist dlEPU_National if year==2013 & month==10,  width(.25) fc(none) fraction xlabel(,labsize(large)) xtitle(,size(large)) ylabel(,labsize(large)) ytitle(,size(large)) xline(`med', lc(red)))
graph export "Results/hist_shutdown2013.png", height(600) width(900) replace

***Shutdown 2018
sum dlEPU_National if year==2018 & month==12,d
local med = r(p50)
di `med'
twoway (hist dlEPU_National if year==2018 & month==12,  width(.25) fc(none) fraction xlabel(,labsize(large)) xtitle(,size(large)) ylabel(,labsize(large)) ytitle(,size(large)) xline(`med', lc(red)))
graph export "Results/hist_shutdown2018.png", height(600) width(900) replace

***9/11
sum dlEPU_National if year==2001 & month==9,d
local med = r(p50)
di `med'
twoway (hist dlEPU_National if year==2001 & month==9,  width(.25) fc(none) fraction xlabel(,labsize(large)) xtitle(,size(large)) ylabel(,labsize(large)) ytitle(,size(large)) xline(`med', lc(red)))
graph export "Results/hist_911.png", height(600) width(900) replace

***Brexit
sum dlEPU_National if year==2016 & month==6,d
local med = r(p50)
di `med'
twoway (hist dlEPU_National if year==2016 & month==6,  width(.25) fc(none) fraction xlabel(,labsize(large)) xtitle(,size(large)) ylabel(,labsize(large)) ytitle(,size(large)) xline(`med', lc(red)))
graph export "Results/hist_brexit.png", height(600) width(900) replace

***Trump Election
sum dlEPU_National if year==2016 & month==11,d
local med = r(p50)
di `med'
twoway (hist dlEPU_National if year==2016 & month==11,  width(.25) fc(none) fraction xlabel(,labsize(large)) xtitle(,size(large)) ylabel(,labsize(large)) ytitle(,size(large)) xline(`med', lc(red)))
graph export "Results/hist_trump.png", height(600) width(900) replace


******************************************************************************************************
*****Figure 4: State Case Studies
******************************************************************************************************
gen quarter = floor((month-1)/3)+1
gen yq = year + (quarter-1)/4
collapse EPU_National EPU_State, by(state year quarter yq)

twoway (line EPU_National EPU_State yq if state=="CA" & (year>=1997 & year<=2005)), xlabel(1997(1)2005)

twoway (line EPU_National EPU_State yq if state=="KS" & (year>=2010 & year<=2016)), xlabel(2010(1)2016)

twoway (line EPU_National EPU_State yq if state=="LA" & (year>=2001 & year<=2007)), xlabel(2001(1)2007)

twoway (line EPU_National EPU_State yq if state=="MI" & (year>=2005 & year<=2014)), xlabel(2005(1)2014)

